﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace CallCenter.Data.BizUtilities
//{
//   public class Dummy
//    {
//        //public ReturnMessage<InvoiceVM> InsertToInvoice(InvoiceVM model)
//        //{
//        //    var returnMessage = new ReturnMessage<InvoiceVM>();
//        //    //  if(this.ValidateScratchPadModel(model))
//        //    //   {


//        //    var id = this.Insert(model.userId, model.companyId, model.productRequestId, model.contactId, model.employeeId, model.invoiceDate, model.description, model.period, model.term, model.notes);
//        //    if (id == -1)
//        //    {
//        //        returnMessage.Message = "We cannot insert data to database";
//        //        returnMessage.Status = false;
//        //    }
//        //    else
//        //    {
//        //        model.id = id;
//        //        returnMessage.Status = true;
//        //    }
//        //    return returnMessage;
//        //}

//        public ReturnMessage<InvoiceVM> UpdateToInvoice(InvoiceVM model)
//        {
//            var returnMessage = new ReturnMessage<InvoiceVM>();
//            //  if(this.ValidateScratchPadModel(model))
//            //   {
//            var id = this.Update(model.id, model.userId, model.companyId, model.productRequestId, model.contactId, model.employeeId, model.invoiceDate, model.description, model.period, model.term, model.notes);
//            if (id == -1)
//            {
//                returnMessage.Message = "We cannot insert data to database";
//                returnMessage.Status = false;
//            }
//            else
//            {
//                model.id = id;
//                returnMessage.Status = true;
//            }
//            return returnMessage;
//        }


//        //assign placeholder for the values in the table to insert
//        public int Insert(
//            int userId,
//            int companyId,
//            int productRequestId,
//            int contactId,
//            int employeeId,
//            DateTime invoiceDate,
//            string description,
//            int period,
//            int term,
//            string notes
//            )
//        {
//            int nRtn = -1;
//            string sql = "INSERT INTO ccInvoice" +
//                 "(userId, productRequestId, companyId, contactId, employeeId, invoiceDate, description, period, term, notes)" +
//             " VALUES(@userId, @productRequestId, @companyId, @contactId, @employeeId, @invoiceDate, @description, @period, @term, @notes)" +
//             " SELECT @pResult =@@IDENTITY";


//            using (var cmd = this.Factory.GetCommand(sql))
//            {
//                this.Factory.AddParameter(cmd, "@userId", SqlDbType.Int, 10, userId);
//                this.Factory.AddParameter(cmd, "@companyId", SqlDbType.Int, 10, companyId);
//                this.Factory.AddParameter(cmd, "@contactId", SqlDbType.Int, 10, contactId);
//                this.Factory.AddParameter(cmd, "@productRequestId", SqlDbType.Int, 10, productRequestId);
//                this.Factory.AddParameter(cmd, "@employeeId", SqlDbType.Int, 10, employeeId);
//                this.Factory.AddParameter(cmd, "@invoiceDate", SqlDbType.SmallDateTime, 10, invoiceDate);
//                this.Factory.AddParameter(cmd, "@description", SqlDbType.NVarChar, 10, description);
//                this.Factory.AddParameter(cmd, "@period", SqlDbType.NVarChar, 10, period);
//                this.Factory.AddParameter(cmd, "@term", SqlDbType.Int, 10, term);
//                this.Factory.AddParameter(cmd, "@notes", SqlDbType.NVarChar, 10, notes);
//                var param = this.Factory.AddParameter(cmd, "@pResult", System.Data.SqlDbType.NVarChar, 500, null);
//                param.Direction = System.Data.ParameterDirection.Output;

//                this.Factory.ExecuteNonQuery(cmd);
//                nRtn = Convert.ToInt32(param.Value);
//            }
//            return nRtn;

//        }

//        public int Update(
//            int id,
//           int userId,
//           int companyId,
//           int productRequestId,
//           int contactId,
//           int employeeId,
//           DateTime invoiceDate,
//           string description,
//             int period,
//            int term,
//            string notes
//           )
//        {
//            int nRtn = -1;
//            string sql = "UPDATE ccInvoice " +
//                 " SET userId=@userId, productRequestId=@productRequestId, companyId=@companyId, " +
//                 " contactId=@contactId, employeeId=@employeeId, invoiceDate=@invoiceDate, description=@description, " +
//                 " period=@period, term=@term, notes=@notes WHERE @pResult=@ID ";


//            using (var cmd = this.Factory.GetCommand(sql))
//            {
//                this.Factory.AddParameter(cmd, "@userId", SqlDbType.Int, 10, userId);
//                this.Factory.AddParameter(cmd, "@companyId", SqlDbType.Int, 10, companyId);
//                this.Factory.AddParameter(cmd, "@contactId", SqlDbType.Int, 10, contactId);
//                this.Factory.AddParameter(cmd, "@productRequestId", SqlDbType.Int, 10, productRequestId);
//                this.Factory.AddParameter(cmd, "@employeeId", SqlDbType.Int, 10, employeeId);
//                this.Factory.AddParameter(cmd, "@invoiceDate", SqlDbType.SmallDateTime, 10, invoiceDate);
//                this.Factory.AddParameter(cmd, "@description", SqlDbType.NVarChar, 10, description);
//                this.Factory.AddParameter(cmd, "@period", SqlDbType.NVarChar, 10, period);
//                this.Factory.AddParameter(cmd, "@term", SqlDbType.Int, 10, term);
//                this.Factory.AddParameter(cmd, "@notes", SqlDbType.NVarChar, 10, notes);

//                this.Factory.AddParameter(cmd, "@id", SqlDbType.Int, 10, id);
//                this.Factory.ExecuteNonQuery(cmd);

//            }
//            nRtn = id;
//            return nRtn; //retruning the data stored in the table
//        }


//        public void Delete(int nInvoice) //delete the row of data using the id passed to the function
//        {
//            string sql = "DELETE FROM ccInvoice" +
//                 " WHERE ID = @ID ";



//            using (var cmd = this.Factory.GetCommand(sql))
//            {
//                this.Factory.AddParameter(cmd, "@ID", SqlDbType.Int, 10, nInvoice);
//                this.Factory.ExecuteTable(sql);
//            }

//        }

//        public void DeleteAll() //delete all the rows in the data.
//        {
//            string sql = "DELETE FROM ccInvoice";
//            this.Factory.ExecuteTable(sql);
//        }

//        public DataTable GetAll()
//        {
//            string sql = "SELECT * FROM ccInvoice";

//            return this.Factory.ExecuteTable(sql);
//        }

//        public DataTable GetAll(int invceId)
//        {
//            string sql = "SELECT * FROM ccInvoice where id=@ID";



//            using (var cmd = this.Factory.GetCommand(sql))
//            {
//                this.Factory.AddParameter(cmd, "@ID", SqlDbType.Int, 10, invceId);
//            }
//            return this.Factory.ExecuteTable(sql);
//        }

//        public List<CompanyGridViewModel> GetAllCompanies()
//        {

//            string sql = "select id,name  from ddlCompany";


//            return this.Factory.ExecuteObjects<CompanyGridViewModel>(sql);

//        }
//        public DataTable GetAllGrid()
//        {
//            string sql = "SELECT i.*, (SELECT TOP 1 lastName+', '+firstName as empName FROM ddlEmployees e " +
//                " INNER JOIN ccContacts on ccContacts.id = e.contactId WHERE ccContacts.id = i.employeeId) as empName, " +
//                " cp.product as productName, c.name as compName, cc.lastName+', '+cc.firstName as clientContName  from ccInvoice i " +
//                " INNER JOIN ddlProductRequests pr on pr.id= i.productRequestId " +
//                " INNER JOIN ddlProducts cp on cp.id = pr.productId " +
//                " INNER JOIN ddlCompany c on c.id = i.companyId " +
//                " LEFT JOIN ddlEmployees e on e.contactId = i.employeeId " +
//                " LEFT JOIN ccContacts cc on cc.id = i.contactId ";

//            return this.Factory.ExecuteTable(sql);


//        }
//        public DataRow Invoic2PDF(int invoiceId)
//        {

//            string sql = " SELECT i.*, c.streetOne, c.streetTwo, c.city as compCity, " +
//                                     " (SELECT TOP 1 state from ddlStates INNER JOIN ddlcompany on " +
//                                     " ddlcompany.stateId = ddlStates.id) as compState, " +
//                                     " (SELECT TOP 1 lastName+', '+firstName as empName FROM ddlEmployees e " +
//                                     " INNER JOIN ccContacts on ccContacts.id = e.contactId " +
//                                     " WHERE ccContacts.id = i.employeeId) as empName, " +
//                                     " cp.product as productName, c.name as compName, " +
//                                     " cc.lastName+', '+cc.firstName as clientContName from ccInvoice i " +
//                                     " INNER JOIN ddlProductRequests pr on pr.id= i.productRequestId " +
//                                     " INNER JOIN ddlProducts cp on cp.id = pr.productId " +
//                                     " INNER JOIN ddlCompany c on c.id = i.companyId " +
//                                     " LEFT JOIN ddlEmployees e on e.contactId = i.employeeId " +
//                                     " LEFT JOIN ccContacts cc on cc.id = i.contactId " +
//                                     " WHERE i.id =" + invoiceId;
//            return this.Factory.ExecuteRecord(sql);

//            //da.Fill(dt);

//            //if (dt.Rows.Count == 1)
//            //    return dt.Rows[0];
//            //else
//            //    return null;


//        }
//        public DataTable GetContactId(int invoiceId)
//        {
//            string sql = "SELECT DISTINCT i.contactId FROM ccInvoice i " +
//                                      "INNER JOIN ddlCompanyContacts ct on ct.companyId = i.companyId " +
//                                      "where ct.emailInvoice = 'true' and i.id=" + invoiceId;

//            return this.Factory.ExecuteTable(sql);

//        }

//    }
//}

//    }
//}
